<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
    <h4>打印出a-b年中所有的闰年，并以每行四个数的形式输出</h4>
    <input type="text" id="num1" placeholder="输入数字a" />
    <input type="text" id="num2" placeholder="输入数字b" />
    <button id="btn">判断</button>
    <script>
      function calc(a,b){
        var tag = 0;
      for (var i = a; i <= b; i++) {
        if ((i % 4 == 0 && i % 100 != 0) || i % 400 == 0) {
          ++tag;
          document.write(i + "  ");
          if (tag % 4 == 0) document.write("<br>");
        }
      }
    }

    var num_1 = document.getElementById("num1");
      var num_2 = document.getElementById("num2");
      btn.onclick = function () {
        var a = parseInt(num_1.value);
        var b = parseInt(num_2.value);

        calc(a, b);
      };
      
    </script>
  </body>
</html>
